/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.nus.dataaccess.dao.base;

import com.nus.constant.ConstantStatus;
import java.io.Serializable;
import java.util.Date;

/**
 *
 * @author robin.foe
 */
public abstract class BaseEntity implements Serializable, Cloneable {
    
    public abstract Serializable getPk();
    
    private String status;
    public String getStatus() {return status;}
    public void setStatus(String status) {this.status = status;}
    public String getStatusAsDisplay(){return (ConstantStatus.ACTIVE.equals(status)) ? "Active" : "Deleted";}
    public boolean isActive(){return ConstantStatus.ACTIVE.equals(status);}
    public void toggleStatus() {
    	this.setStatus(isActive()? ConstantStatus.DELETED : ConstantStatus.ACTIVE );
    }
    
    private Long createdById;
    public Long getCreatedById() {return createdById;}
    public void setCreatedById(Long createdById) {this.createdById = createdById;}

    private Date createdDateTime;
    public Date getCreatedDateTime() {return createdDateTime;}
    public void setCreatedDateTime(Date createdDateTime) {this.createdDateTime = createdDateTime;}

	//user_account id
    private Long modifiedById;
    public Long getModifiedById() {return modifiedById;}
    public void setModifiedById(Long modifiedById) {this.modifiedById = modifiedById;}

    private Date modifiedDateTime;
    public Date getModifiedDateTime() {return modifiedDateTime;}
    public void setModifiedDateTime(Date modifiedDateTime) {this.modifiedDateTime = modifiedDateTime;}
    
    
    @Override
    public Object clone() {
        try {
            return super.clone();
        } catch (CloneNotSupportedException e) {            
            e.printStackTrace();
            return null;
        }
    }
    
	
    @Override
    public int hashCode() {return getPk() != null ? getPk().hashCode() : 0;}

    @Override
    public boolean equals(Object object) {    	
        if (object == null || object.getClass() != this.getClass()) 
        	return false;  
        
        BaseEntity other = (BaseEntity) object;        
        return (this.getPk() == null) ? other.getPk() == null : this.getPk().equals(other.getPk());        
    }
    
    @Override
    public String toString() {
    	try{
            if(this == null)
                return "null";

            return this.getClass().getName() + "[PK: " + this.getPk() != null ? this.getPk().toString(): "null" + "]";
    	}catch(Exception e){/*IGNORED*/}
    	return "null";
    	
    }
    
    public boolean isPkSet(){
    	return !(this.getPk()== null);
    }
    
}
